<template>
  <div class="songs-container">
    <div class="top-wrap">
      <div class="img-wrap">
        <!-- 封面 -->
        <img
          src="https://p2.music.126.net/J9gVNFFQ6ygtkzubXCTV_w==/109951165135339093.jpg?param=200y200"
        />
      </div>

      <div class="info-wrap">
        <!-- 名字 -->
        <div class="title-wrap">
          <p class="title">rzi2016 每日推荐</p>
        </div>
        <div class="creator-wrap">
          <!-- 头像 -->
          <img
            class="avatar"
            src="http://p1.music.126.net/MbE_vwfa9vl37r58TSdCTw==/109951165134619076.jpg?param=80y80"
          />
          <!-- 名字 -->
          <p class="creator">rzi2016</p>
          <!-- 时间 -->
          <p class="create-time">{{ $utils.formatDate(Date.parse(new Date()), 'yyyy-MM-dd') }} 创建</p>
        </div>

        <div class="action-wrap">
          <div class="n-button button">
            <Icon class="icon middle" color="white" type="play-round" />
            <span class="middle" @click="toPlayAll">播放全部</span>
          </div>
        </div>

        <div class="desc-wrap">
          <p class="desc">
            <span>标签：轻音乐/日语/欧美/电子/旅行/ACG</span>
          </p>
          <p class="desc">
            <span
              class="value"
            >简介：二十岁的时候，千万不要花精力和时间去犹豫和纠结什么选择是最好的，因为没有人知道，有想法就大胆地去尝试，感受不同的生活，多尝试工作类型、多读书、多旅行、多谈恋爱、多结交朋友。把这些该交的学费都交了，如此一来，三十岁以后，你才有可能从容不迫地过自己想要的生活。</span>
          </p>
        </div>
      </div>
    </div>

    <!-- 底部的table -->
    <div class="song-card-wrap" v-if="songs && songs.length !== 0">
      <SongCard :songs="songs" />
    </div>
    <Empty class="empty" v-else>暂无结果</Empty>
  </div>
</template>

<script>
import { getRzRecommendSongs, getSongDetail } from 'network/request'
import { mapState, mapMutations, mapActions } from '@/store/helper/music'
export default {
  name: 'dailyRecommend',
  data() {
    return {
      songs: [],
    }
  },

  created() {
    this._getRecommendSongs()
  },
  methods: {
    // 获取每日推荐
    async _getRecommendSongs() {
      const { data } = await getRzRecommendSongs()
      // 获取歌单详情
      const newSongs = await this._getPlaylistDetail(data.dailySongs.map((x) => x.id))
      this.songs = newSongs
    },
    // 获取歌单详情
    async _getPlaylistDetail(trackIds) {
      let params = this.$utils.songDetailParams(trackIds)
      const { songs } = await getSongDetail(params)
      return songs.map((x) => this.$utils.createSong(x))
    },
    onClickSong(index) {
      this.startSong(this.songs[index])
      this.setPlaylist(this.songs)
    },
    toPlayAll() {
      this.startSong(this.songs[0])
      this.setPlaylist(this.songs)
    },
    ...mapMutations(['setPlaylist']),
    ...mapActions(['startSong']),
  },
  computed: {
    ...mapState(['currentSong']),
  },
}
</script>

<style lang="scss" scoped>
.songs-container {
  padding: 12px;

  .top-wrap {
    display: flex;
    padding: 36px;

    .img-wrap {
      width: 200px;
      height: 200px;
      margin-right: 24px;

      img {
        width: 100%;
        height: 100%;
      }
    }

    .info-wrap {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      flex: 1;

      .title-wrap {
        display: flex;
        align-items: center;
        margin-bottom: 12px;

        .title {
          font-size: $font-size-lg;
          color: var(--font-color-white);
        }
      }

      .action-wrap {
        margin-bottom: 18px;

        .n-button {
          display: inline-block;
          padding: 5px 16px;
          border: 1px solid var(--button-border-color);
          border-radius: 2px;
          text-align: center;
          cursor: pointer;
        }

        .button {
          background: #f95043;
          background: linear-gradient(to right, #fa5143, #f44d41, #d53b32);
          color: #fbdfdd;
          border: none;

          .icon {
            margin-right: 4px;
          }

          .middle {
            vertical-align: middle;
          }
        }
      }

      .creator-wrap {
        display: flex;
        align-items: center;
        margin-bottom: 18px;

        .avatar {
          width: 30px;
          height: 30px;
          border-radius: 50%;
          margin-right: 8px;
        }

        .creator {
          margin-right: 8px;
        }

        .create-time {
          font-size: $font-size-sm;
        }
      }

      .desc {
        margin-bottom: 8px;

        .label {
          display: inline-block;
          margin-right: 8px;
        }

        .value {
          color: var(--font-color-grey2);
          @include text-ellipsis-multi(3);
        }
      }
    }
  }
}
</style>
